//
//  MHShareCircleViewController.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/4/27.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHShareCircleViewController.h"
#import "MHShareCircleViewModel.h"
#import "MHShareQRCodeView.h"
#import "MHCommonCell.h"
#import "MHQRCodeModel.h"

@interface MHShareCircleViewController ()
@property(nonatomic, strong) MHShareCircleViewModel *viewModel;
@property(nonatomic, strong) MHShareQRCodeView *shareQrCodeView;

@end

@implementation MHShareCircleViewController
@dynamic viewModel;

- (void)viewDidLoad {
    [super viewDidLoad];
    @weakify(self);
    [[self.viewModel.fetchQrCodeLinkCommond execute:nil] subscribeNext:^(MHQRCodeModel *model) {
        @strongify(self);
        self.viewModel.qrCodeModel = model;
        [self.shareQrCodeView.qrcodeImageView yy_setImageWithURL:model.linkUrl placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
    }];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)configureCell:(MHCommonCell *)cell atIndexPath:(NSIndexPath *)indexPath withObject:(id)object
{
    MHCommonGroupViewModel *groupViewModel = self.viewModel.dataSource[indexPath.section];
//    id object = groupViewModel.itemViewModels[indexPath.row];
    if (indexPath.row == (groupViewModel.itemViewModels.count - 1)) {
        __weak __typeof(self)weakSelf = self;
        MHCommonItemViewModel *common =   (MHCommonItemViewModel *)object;
        common.operation = ^{
            weakSelf.zh_popupController = [zhPopupController new];
            weakSelf.shareQrCodeView.nickNameLabel.text = [NSString stringWithFormat:@"%@的圈子",weakSelf.viewModel.circleInfo.ownerName];
            weakSelf.shareQrCodeView.circleName.text = weakSelf.viewModel.circleInfo.title;
            [weakSelf.shareQrCodeView.avaterImageView yy_setImageWithURL:[NSURL URLWithString:weakSelf.viewModel.circleInfo.fullOwnerFace] placeholder:MHDefaultAvatar(MHDefaultAvatarTypeDefualt)];
            weakSelf.shareQrCodeView.width = weakSelf.view.width * 0.8;
            weakSelf.shareQrCodeView.height = weakSelf.shareQrCodeView.width * (790/612.0);
            [weakSelf.zh_popupController presentContentView:weakSelf.shareQrCodeView];
        };
    
    }
    [super configureCell:cell atIndexPath:indexPath withObject:object];
}

-(MHShareQRCodeView *)shareQrCodeView
{
    if (!_shareQrCodeView) {
      _shareQrCodeView =  [MHShareQRCodeView mh_viewFromXib];
//        _shareQrCodeView.qrCodeWebView.scrollView.scrollEnabled = NO;
//        _shareQrCodeView.qrCodeWebView.scrollView.bounces = NO;
//        _shareQrCodeView.qrCodeWebView.scrollView.contentSize = CGSizeMake(125, 125);
//        _shareQrCodeView.qrCodeWebView.scalesPageToFit = YES;
    }
    return _shareQrCodeView;
}


@end
